package com.jackykeke.kdatabasedemo.db.helper

import android.content.ContentValues
import android.content.Context
import android.database.Cursor
import android.database.sqlite.SQLiteOpenHelper
import com.jackykeke.kdatabasedemo.db.*

open abstract class BaseDatabaseHelper : SQLiteOpenHelper {

    /**
     * 是否升级成功
     */
    protected var mIsUpgrade = true

    constructor(context: Context?, name: String?, version: Int) : super(
        context,
        name,
        null,
        version
    )


    open fun insert(vararg insertParams: InsertParams): Boolean {
        return DatabaseUtils.insert(this, *insertParams)
    }


    /**
     * 插入 insert(这里用一句话描述这个方法的作用) (这里描述这个方法适用条件 – 可选)
     *
     * @param tableName
     * @param initialValues
     * @return
     * @throws DatabaseException
     * long
     * @exception
     * @since 1.0.0
     */
    @Throws(DatabaseException::class)
    open fun insert(tableName: String?, initialValues: ContentValues?): Long {
        return DatabaseUtils.insert(this, tableName, initialValues)
    }


    @Throws(DatabaseException::class)
    open fun delete(list: List<DeleteParams>?): Boolean {
        return DatabaseUtils.delete(this, list)
    }


    @Throws(DatabaseException::class)
    open fun update(list: List<UpdateParams>?): Boolean {
        return DatabaseUtils.update(this, list)
    }


    open fun query(
        tableName: String, projection: Array<String>?, selection: String,
        selectionArgs: Array<String>, sortOrder: String?
    ): Cursor? {

        return query(tableName, projection, selection, selectionArgs, null, null, sortOrder)
    }


    /**
     * 查询 query(这里用一句话描述这个方法的作用) (这里描述这个方法适用条件 – 可选)
     *
     * @param tableName
     * @param projection
     * @param selection
     * @param selectionArgs
     * @param groupBy
     * @param having
     * @param sortOrder
     * @return Cursor
     * @exception
     * @since 1.0.0
     */
    open fun query(
        tableName: String, projection: Array<String>?,
        selection: String?, selectionArgs: Array<String>?, groupBy: String?,
        having: String?, sortOrder: String?
    ): Cursor? {
        return DatabaseUtils.query(
            this, tableName, projection, selection,
            selectionArgs, groupBy, having, sortOrder
        )
    }

}